package com.freeseed.model.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.freeseed.model.entity.ProvinceDtl;
import com.freeseed.model.mapper.ProvinceDtlMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Allwayz
 * @since 2020-03-20
 */
@Slf4j
@RestController
@RequestMapping("provinces")
public class ProvinceDtlController {
    @Autowired
    private ProvinceDtlMapper provinceDtlMapper;

    @GetMapping
    public List<ProvinceDtl> getProvinceDtlList(){
        List<ProvinceDtl> provinceDtlList = provinceDtlMapper.selectList(new QueryWrapper<>());
        return provinceDtlList;
    }

    @GetMapping("{Id}")
    public ProvinceDtl getProvinceDtlById(@PathVariable int Id){
        ProvinceDtl provinceDtl = provinceDtlMapper.selectById(Id);
        return provinceDtl;
    }

    @PostMapping
    public ProvinceDtl addProvinceDtl(ProvinceDtl provinceDtl){
        provinceDtlMapper.insert(provinceDtl);
        return provinceDtl;
    }

    @PutMapping
    public ProvinceDtl updateProvinceDtl(ProvinceDtl provinceDtl){
        provinceDtlMapper.update(provinceDtl,new UpdateWrapper<ProvinceDtl>().eq("province_dtl_id",provinceDtl.getProvinceDtlId()));
        return provinceDtl;
    }

    @DeleteMapping("{Id}")
    public void deleteProvinceDtl(@PathVariable int Id){
        provinceDtlMapper.deleteById(Id);
    }
}
